package com.xauto.pioneer.appuser.adapter;

import android.app.Activity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.xauto.pioneer.appuser.R;
import com.xauto.pioneer.appuser.model.VoucherDetailInfo;

/**
 * Created by Lemon on 2015/12/11.
 * Desc:优惠券列表 适配器
 */
public class VoucherAdapter extends AbsAdapter<VoucherDetailInfo> {
    private boolean is_used_tag;
    private boolean isFromOrder;
    private int selectPosition = -1;

    public void setFromOrder(boolean fromOrder) {
        isFromOrder = fromOrder;
    }

    public void setSelectPosition(int selectPosition) {
        this.selectPosition = selectPosition;
    }
    public void setIs_used_tag(boolean is_used_tag) {
        this.is_used_tag = is_used_tag;
    }

    public VoucherAdapter(Activity context, int layout) {
        super(context, layout);
    }

    @Override
    public ViewHolder<VoucherDetailInfo> getHolder() {
        return new TemplateViewHolder();
    }


    private class TemplateViewHolder implements ViewHolder<VoucherDetailInfo> {
        private ImageView imgLogo;
        private TextView tvVoucherDeadline;
        private TextView tvVoucherMoney;
        private TextView tvVoucherLimit;
        private TextView tvVoucherDeadlineHint;
        private TextView tvVoucherMoneyHint;

        @Override
        public void initViews(View v, int position) {
            imgLogo = (ImageView) v.findViewById(R.id.imgLogo);
            tvVoucherDeadline = (TextView) v.findViewById(R.id.tvVoucherDeadline);
            tvVoucherMoney = (TextView) v.findViewById(R.id.tvVoucherMoney);
            tvVoucherLimit = (TextView) v.findViewById(R.id.tvVoucherLimit);
            tvVoucherDeadlineHint = (TextView) v.findViewById(R.id.tvVoucherDeadlineHint);
            tvVoucherMoneyHint = (TextView) v.findViewById(R.id.tvVoucherMoneyHint);
        }

        @Override
        public void updateData(VoucherDetailInfo voucherDetailInfo, int position) {
            tvVoucherDeadline.setText(voucherDetailInfo.validate_date_description);
            tvVoucherMoney.setText(voucherDetailInfo.discount_amount);
            tvVoucherLimit.setText(voucherDetailInfo.limit_description);
            if (is_used_tag){
                tvVoucherDeadlineHint.setTextColor(context.getResources().getColor(R.color.main_gray));
                tvVoucherDeadline.setTextColor(context.getResources().getColor(R.color.main_gray));
                tvVoucherMoney.setTextColor(context.getResources().getColor(R.color.main_gray));
                tvVoucherMoneyHint.setTextColor(context.getResources().getColor(R.color.main_gray));
            }else {
                tvVoucherDeadlineHint.setTextColor(context.getResources().getColor(R.color.main_black));
                tvVoucherDeadline.setTextColor(context.getResources().getColor(R.color.main_black));
                tvVoucherMoney.setTextColor(context.getResources().getColor(R.color.red));
                tvVoucherMoneyHint.setTextColor(context.getResources().getColor(R.color.red));
            }
            if (isFromOrder){
                imgLogo.setVisibility(View.VISIBLE);
                if ( position == selectPosition){
                    imgLogo.setImageResource(R.mipmap.ic_coupon_checked);
                }
            }else {
                imgLogo.setVisibility(is_used_tag ? View.VISIBLE : View.GONE);
                imgLogo.setImageResource(R.mipmap.ic_coupon_used);
            }
        }

        @Override
        public void doOthers(VoucherDetailInfo voucherDetailInfo, int position) {

        }
    }
}
